<?php
header('content-type:text/html;charset=utf-8');

require 'login_db_connect.php';
 

if (isset($_POST['username'])&&isset($_POST['pwd'])){//登录表单已提交
   
    $user=$_POST["username"];
    $pwd=$_POST["pwd"];
    
    if ($user=='' || $pwd==''){
        exit('账号或密码不能为空');
    }else {
        $sql="insert into user(username,password) values ('$user','$pwd');";
        $select="select username from user where username='$user'";
        $result=mysqli_query($con, $select);
        $row=mysqli_num_rows($result);
        if(!$row){
            if (mysqli_query($con,$sql)){
                echo "<script>alert('注册成功，请登录');location='./login.php'</script>";
            }else{
                echo "<script>alert('注册失败，请重新注册');location='./regsiter.php'</script>";
            }
        }else{
            echo "<script>alert('该用户已经存在，请直接登录');location='./login.php'</script>";
        }
    }  
}
 
